package com.share.pattern.observer.v3;

import java.util.Scanner;

/**
 * 
 * @author Johnny Tam * v0.3版本 观察者模式
 * 
 *         前台具体的通知者，也应该抽象，抽象具体通知者
 */
public class ObserverDemoV03 {

	public static void main(String[] args) {
		// 前台
		Secretary sec = new Secretary();

		// 看股票的同事
		StockObserver tongshi1 = new StockObserver("曹老师", sec);
		StockObserver tongshi2 = new StockObserver("薇薇老师", sec);

		// 看NBA同事
		NBAObserver tongshi3 = new NBAObserver("姚明老师", sec);
		NBAObserver tongshi4 = new NBAObserver("檀老师", sec);

		// 前台记下同事
		sec.Attach(tongshi1);
		sec.Attach(tongshi2);
		sec.Attach(tongshi3);

		// 发现老板回来了， 赶紧通知
		sec.setAction("老板回来了！");
		// 通知已经登记的同事
		sec.Notify();

		// 老板
		Boss boss = new Boss();

		// 看股票的同事
		StockObserver tongshi1_1 = new StockObserver("曹老师", boss);
		StockObserver tongshi2_1 = new StockObserver("薇薇老师", boss);

		// 看NBA同事
		NBAObserver tongshi3_1 = new NBAObserver("姚明老师", boss);
		NBAObserver tongshi4_1 = new NBAObserver("檀老师", boss);

		// 老板登记了同事
		boss.Attach(tongshi1_1);
		boss.Attach(tongshi2_1);
		boss.Attach(tongshi3_1);

		boss.Attach(tongshi4_1);
		boss.Detach(tongshi4_1);// 消除了登记记录

		boss.setAction("我胡汉三又回来了！");
		boss.Notify();	

	}

}
